<template>
  <el-dialog
    class="msui-dialog"
    v-bind="bind"
    v-on="dialogFunction"
    :visible.sync="options.bind.show"
    :fullscreen="fullscreen"
  >
    <template #title>
      <div class="title-content">
        <span class="el-dialog__title">{{ bind.title }}</span>
        <div class="right">
          <span v-if="bind.fullscreen == true" class="el-icon-full-screen" @click="fullscreen = !fullscreen"></span>
          <span class="el-icon-close" @click="close"></span>
        </div>
      </div>
    </template>
    <slot></slot>
    <div v-if="bind.showFoot == false ? false : true" slot="footer" class="dialog-footer">
      <slot v-if="$scopedSlots.footer" name="footer"></slot>
      <div v-else>
        <el-button
          :size="bind.size || 'medium'"
          type="primary"
          @click="confirm"
          :disabled="bind.disabled || false"
          :loading="bind.loading || false"
          >确定</el-button
        >
        <el-button :size="bind.size || 'medium'" @click="options.bind.show = false" :disabled="bind.loading"
          >取消</el-button
        >
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { elDialog } from '../msui-utils/msui-default'
export default {
  name: 'MsuiDialog',
  props: {
    options: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      fullscreen: false
    }
  },
  computed: {
    bind() {
      return Object.assign({}, elDialog, this.options.bind)
    },
    dialogFunction() {
      return this.options.vOn || {}
    }
  },
  watch: {
    fullscreen() {
      if (this.dialogFunction.fullScreenChange) {
        this.dialogFunction.fullScreenChange(this.fullscreen)
      }
    }
  },
  methods: {
    open() {
      this.options.bind.show = true
    },
    close() {
      this.options.bind.show = false
    },
    confirm() {
      if (this.dialogFunction.confirm instanceof Function) {
        this.dialogFunction.confirm()
        return
      }
      this.bind.show = false
    }
  }
}
</script>
<style scoped>
::v-deep .el-dialog__header {
  padding: 15px;
}
::v-deep .el-dialog__footer {
  padding-top: 20px;
}
::v-deep .el-dialog__title {
  background: #f2f3f5;
  color: var(--background-primary);
  font-size: 14px;
  font-weight: 350;
  padding: 0px 16px;
  border-radius: 100px;
}
::v-deep .el-dialog__body {
  padding-top: 0 !important;
  border-top: 1px solid #dcdee2;
  border-bottom: 1px solid #dcdee2;
  overflow: auto;
}
.title-content {
  display: flex;
  justify-content: space-between;
}
.right {
  display: flex;
  align-items: center;
}
.el-icon-full-screen,
.el-icon-close {
  padding-right: 10px;
  cursor: pointer;
  color: #909399;
}
.el-icon-close {
  font-size: 24px;
}
</style>
